from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-10 14:04:32.797140
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 10, Dec, 2021
Time: 14:04:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.4427
Nobs: 501.000 HQIC: -47.9030
Log likelihood: 5766.15 FPE: 1.16668e-21
AIC: -48.2002 Det(Omega_mle): 9.76571e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.370841 0.080437 4.610 0.000
L1.Burgenland 0.094662 0.044228 2.140 0.032
L1.Kärnten -0.115757 0.022687 -5.102 0.000
L1.Niederösterreich 0.172514 0.091490 1.886 0.059
L1.Oberösterreich 0.130766 0.092802 1.409 0.159
L1.Salzburg 0.282586 0.047399 5.962 0.000
L1.Steiermark 0.016957 0.061231 0.277 0.782
L1.Tirol 0.106664 0.049460 2.157 0.031
L1.Vorarlberg -0.085157 0.043560 -1.955 0.051
L1.Wien 0.032632 0.083256 0.392 0.695
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.009928 0.178379 0.056 0.956
L1.Burgenland -0.051560 0.098081 -0.526 0.599
L1.Kärnten 0.036949 0.050311 0.734 0.463
L1.Niederösterreich -0.216540 0.202892 -1.067 0.286
L1.Oberösterreich 0.482037 0.205802 2.342 0.019
L1.Salzburg 0.313426 0.105114 2.982 0.003
L1.Steiermark 0.099994 0.135789 0.736 0.461
L1.Tirol 0.307389 0.109684 2.802 0.005
L1.Vorarlberg 0.008130 0.096599 0.084 0.933
L1.Wien 0.020617 0.184632 0.112 0.911
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219860 0.040991 5.364 0.000
L1.Burgenland 0.090660 0.022539 4.022 0.000
L1.Kärnten -0.004719 0.011561 -0.408 0.683
L1.Niederösterreich 0.222106 0.046624 4.764 0.000
L1.Oberösterreich 0.171468 0.047293 3.626 0.000
L1.Salzburg 0.036839 0.024155 1.525 0.127
L1.Steiermark 0.025912 0.031204 0.830 0.406
L1.Tirol 0.075440 0.025205 2.993 0.003
L1.Vorarlberg 0.055752 0.022198 2.512 0.012
L1.Wien 0.108059 0.042428 2.547 0.011
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153165 0.039996 3.830 0.000
L1.Burgenland 0.043437 0.021992 1.975 0.048
L1.Kärnten -0.012203 0.011281 -1.082 0.279
L1.Niederösterreich 0.152463 0.045492 3.351 0.001
L1.Oberösterreich 0.350285 0.046144 7.591 0.000
L1.Salzburg 0.100651 0.023568 4.271 0.000
L1.Steiermark 0.108403 0.030446 3.560 0.000
L1.Tirol 0.085608 0.024593 3.481 0.000
L1.Vorarlberg 0.053642 0.021659 2.477 0.013
L1.Wien -0.036190 0.041398 -0.874 0.382
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.152698 0.076916 1.985 0.047
L1.Burgenland -0.040965 0.042292 -0.969 0.333
L1.Kärnten -0.036267 0.021694 -1.672 0.095
L1.Niederösterreich 0.129420 0.087486 1.479 0.139
L1.Oberösterreich 0.193787 0.088741 2.184 0.029
L1.Salzburg 0.255617 0.045324 5.640 0.000
L1.Steiermark 0.073596 0.058551 1.257 0.209
L1.Tirol 0.130014 0.047295 2.749 0.006
L1.Vorarlberg 0.104301 0.041653 2.504 0.012
L1.Wien 0.040869 0.079612 0.513 0.608
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080575 0.060910 1.323 0.186
L1.Burgenland 0.014611 0.033491 0.436 0.663
L1.Kärnten 0.051418 0.017179 2.993 0.003
L1.Niederösterreich 0.176722 0.069280 2.551 0.011
L1.Oberösterreich 0.341355 0.070273 4.858 0.000
L1.Salzburg 0.050278 0.035892 1.401 0.161
L1.Steiermark -0.007021 0.046367 -0.151 0.880
L1.Tirol 0.123160 0.037453 3.288 0.001
L1.Vorarlberg 0.058577 0.032985 1.776 0.076
L1.Wien 0.112050 0.063045 1.777 0.076
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169416 0.073914 2.292 0.022
L1.Burgenland 0.011292 0.040641 0.278 0.781
L1.Kärnten -0.060822 0.020847 -2.918 0.004
L1.Niederösterreich -0.111845 0.084071 -1.330 0.183
L1.Oberösterreich 0.233611 0.085277 2.739 0.006
L1.Salzburg 0.038030 0.043555 0.873 0.383
L1.Steiermark 0.264009 0.056266 4.692 0.000
L1.Tirol 0.489074 0.045449 10.761 0.000
L1.Vorarlberg 0.070949 0.040027 1.773 0.076
L1.Wien -0.100843 0.076505 -1.318 0.187
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.138399 0.081678 1.694 0.090
L1.Burgenland -0.013152 0.044911 -0.293 0.770
L1.Kärnten 0.064125 0.023037 2.784 0.005
L1.Niederösterreich 0.171184 0.092902 1.843 0.065
L1.Oberösterreich -0.072940 0.094235 -0.774 0.439
L1.Salzburg 0.222124 0.048130 4.615 0.000
L1.Steiermark 0.133953 0.062176 2.154 0.031
L1.Tirol 0.049891 0.050223 0.993 0.321
L1.Vorarlberg 0.141893 0.044232 3.208 0.001
L1.Wien 0.168295 0.084541 1.991 0.047
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.450462 0.045160 9.975 0.000
L1.Burgenland -0.000670 0.024831 -0.027 0.978
L1.Kärnten -0.013166 0.012737 -1.034 0.301
L1.Niederösterreich 0.178857 0.051365 3.482 0.000
L1.Oberösterreich 0.270122 0.052102 5.184 0.000
L1.Salzburg 0.019496 0.026611 0.733 0.464
L1.Steiermark -0.013354 0.034377 -0.388 0.698
L1.Tirol 0.069243 0.027768 2.494 0.013
L1.Vorarlberg 0.056044 0.024456 2.292 0.022
L1.Wien -0.015500 0.046743 -0.332 0.740
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.027199 0.092093 0.157699 0.139433 0.063931 0.082471 0.015091 0.208758
Kärnten 0.027199 1.000000 -0.036502 0.128701 0.048479 0.072739 0.456602 -0.082148 0.094688
Niederösterreich 0.092093 -0.036502 1.000000 0.278349 0.099248 0.253079 0.051046 0.141109 0.245593
Oberösterreich 0.157699 0.128701 0.278349 1.000000 0.193349 0.284071 0.162367 0.123758 0.181084
Salzburg 0.139433 0.048479 0.099248 0.193349 1.000000 0.119590 0.061513 0.109498 0.064756
Steiermark 0.063931 0.072739 0.253079 0.284071 0.119590 1.000000 0.132186 0.087422 0.004924
Tirol 0.082471 0.456602 0.051046 0.162367 0.061513 0.132186 1.000000 0.063646 0.128549
Vorarlberg 0.015091 -0.082148 0.141109 0.123758 0.109498 0.087422 0.063646 1.000000 -0.012063
Wien 0.208758 0.094688 0.245593 0.181084 0.064756 0.004924 0.128549 -0.012063 1.000000